package com.yanqu.road.server.cmd.activity.jiuzhou;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.jiuzhou.CrossJiuZhouProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.jiuzhou.CrossJiuZhouMgr;
import com.yanqu.road.server.manager.activity.jiuzhou.activity.CrossJiuZhouActivity;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CROSS_JIU_ZHOU_CHOOSE_SKILLID2, desc = "选择棋书")
public class CrossJiuZhouChooseSkillId2Cmd extends CrossCommand {

    private int activityId;

    private int roomId;

    private long opponentUserId;

    private int skillId2;

    private long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossJiuZhouProto.CrossJiuZhouChooseSkillId2ReqMsg reqMsg = CrossJiuZhouProto.CrossJiuZhouChooseSkillId2ReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        roomId = reqMsg.getRoomId();
        opponentUserId = reqMsg.getOpponentUserId();
        skillId2 = reqMsg.getSkillId2();
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossJiuZhouActivity activity = CrossJiuZhouMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_JIU_ZHOU_ACTIVITY_NOT_EXIST;
            return;
        }

        ret = activity.chooseSkillId2ByCmd(playerId, roomId, opponentUserId, skillId2);
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            CrossJiuZhouProto.CrossJiuZhouChooseSkillId2RespMsg.Builder builder = CrossJiuZhouProto.CrossJiuZhouChooseSkillId2RespMsg.newBuilder();
            builder.setRet(ret);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.S_JIU_ZHOU_CHOOSE_SKILLID2_FROM_CROSS, builder));
        }
    }
}
